from selenium import webdriver
from selenium.webdriver.common.by import By
# 1.导入下拉框操作类
from selenium.webdriver.support.select import Select
from time import sleep

driver = webdriver.Firefox()
driver.maximize_window()
driver.implicitly_wait(10)
url = 'file:///C:/Users/tedu/Desktop/NSD2406/html/register.html'
driver.get(url)

"""
sleep(3)
# 定位到下拉框中的上海这个选项，然后点击
driver.find_element(By.CSS_SELECTOR, '[value="sh"]').click()
# 停顿3秒，定位到下拉框中广州这个选项，然后点击
sleep(3)
driver.find_element(By.CSS_SELECTOR, '[value="gz"]').click()
"""
# 定位下拉框
select = driver.find_element(By.CSS_SELECTOR, '#select')
# 2.实例化下拉框对象，传递定位的下拉框
sel = Select(select)
# 3.切换
# 3.1通过下标切换
# 3.2通过value值切换
# 3.3通过显示文本切换
sleep(3)
# sel.select_by_index(1)
# sel.select_by_value('sh')
sel.select_by_visible_text('上海')
sleep(3)
# sel.select_by_index(2)
# sel.select_by_value('gz')
sel.select_by_visible_text('广州')

sleep(3)
driver.quit()